package com.zjitc;

import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import javafx.application.Application;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/6 14:25
 * @description:
 */
public class App2 {

  public static void main(String[] args) {


    //连接数据库
    /*HikariDataSource dataSource=null;

    try {
      dataSource=new HikariDataSource();//new User
      dataSource.setUsername("root");     //setName()  setAge()
      dataSource.setPassword("123456789");
      dataSource.setDriverClassName("com.mysql.jdbc.Driver");
      dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test");

      try {
        Connection connection=dataSource.getConnection();
        System.out.println(connection);
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }finally {
      if (dataSource!=null){
        dataSource.close();
      }
    }*/

    //用Spring方法连接
    ApplicationContext context=new ClassPathXmlApplicationContext("hikariCP-spring-config.xml");
    DataSource bean=context.getBean(DataSource.class);
    try {
      Connection connection=bean.getConnection();
      System.out.println(connection);
    } catch (SQLException e) {
      e.printStackTrace();
    }



  }

}
